#!/bin/bash

# 下载并保存 nvm 安装脚本
curl -L -o /tmp/install_nvm.sh https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh

# 检查文件是否成功下载
if [ ! -f "/tmp/install_nvm.sh" ]; then
  echo "Failed to download nvm installation script."
  exit 1
fi

# 执行 nvm 安装脚本
bash /tmp/install_nvm.sh

# 配置环境变量
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm

# 安装 Node.js 版本 16.20.2
nvm install 16.20.2

# 清理临时文件
rm /tmp/install_nvm.sh